Filter Class Result

Select criteria to view class academic performance

"; try { // First, let's check what data exists in the marks table $check_query = "SELECT COUNT(*) as total_count FROM marks WHERE acyear = :acyear AND term = :term AND klass = :klass"; $check_stmt = $DBcon->prepare($check_query); $check_stmt->execute([ ':acyear' => $acyear, ':term' => $term, ':klass' => $klass ]); $check_result = $check_stmt->fetch(PDO::FETCH_ASSOC); echo ""; if($check_result['total_count'] > 0) { // Get all students in the class $students_query = "SELECT DISTINCT regno FROM marks WHERE acyear = :acyear AND term = :term AND klass = :klass ORDER BY regno"; $students_stmt = $DBcon->prepare($students_query); $students_stmt->execute([ ':acyear' => $acyear, ':term' => $term, ':klass' => $klass ]); $students = $students_stmt->fetchAll(PDO::FETCH_ASSOC); echo ""; // Get all subjects for this class $subjects_query = "SELECT DISTINCT subject FROM marks WHERE acyear = :acyear AND term = :term AND klass = :klass ORDER BY subject"; $subjects_stmt = $DBcon->prepare($subjects_query); $subjects_stmt->execute([ ':acyear' => $acyear, ':term' => $term, ':klass' => $klass ]); $subjects = $subjects_stmt->fetchAll(PDO::FETCH_ASSOC); echo ""; // Debug: Show actual data found echo "
"; echo "Debug Information:
"; echo "Academic Year: $acyear
"; echo "Term: $term
"; echo "Class: $klass
"; echo "Total Records Found: {$check_result['total_count']}
"; echo "Students: " . count($students) . "
"; echo "Subjects: " . count($subjects) . "
"; if(count($students) > 0) { echo "Student RegNos: "; foreach($students as $student) { echo $student['regno'] . ", "; } echo "
"; } if(count($subjects) > 0) { echo "Subjects: "; foreach($subjects as $subject) { echo $subject['subject'] . ", "; } } echo "
"; // Fetch all marks data for efficient processing $marks_query = "SELECT * FROM marks WHERE acyear = :acyear AND term = :term AND klass = :klass"; $marks_stmt = $DBcon->prepare($marks_query); $marks_stmt->execute([ ':acyear' => $acyear, ':term' => $term, ':klass' => $klass ]); $all_marks = $marks_stmt->fetchAll(PDO::FETCH_ASSOC); // Organize marks by student and subject $student_marks = []; $student_totals = []; $student_averages = []; foreach($all_marks as $mark) { $regno = $mark['regno']; $subject = $mark['subject']; $test = $mark['test']; $exam = $mark['exam']; $total = $test + $exam; $student_marks[$regno][$subject] = [ 'test' => $test, 'exam' => $exam, 'total' => $total ]; // Initialize totals if not set if(!isset($student_totals[$regno])) { $student_totals[$regno] = 0; } $student_totals[$regno] += $total; } // Calculate averages foreach($student_totals as $regno => $total) { $subject_count = count($student_marks[$regno]); $student_averages[$regno] = $subject_count > 0 ? $total / $subject_count : 0; } ?>

Class Result Sheet

Raymond Schools Nkpor

Class Result Sheet

Academic Year

Term

Class

Total Students

Total Subjects

'-', 'exam' => '-', 'total' => '-']; ?>
REG NO TOTAL SCORE AVERAGE
Test Exam Total
Class Size:
Students
Subjects Offered:
Subjects
Academic Year:
Term:

_________________________

Class Teacher

_________________________

Principal

_________________________

Date:

No results found for the selected criteria. Please check:
'; echo '
'; echo 'Academic Year: ' . $acyear . '
'; echo 'Term: ' . $term . '
'; echo 'Class: ' . $klass . '
'; echo 'Make sure there are marks entered for this class in the selected academic year and term.'; echo '
'; } } catch(PDOException $e) { echo '
Database error: ' . htmlspecialchars($e->getMessage()) . '
'; } } ?>